from microbit import *

x = 2
y = 2

def on_button_pressed_a():
    global x
    led.unplot(x, y)
    led.unplot(x + 1, y)
    led.unplot(x - 1, y)
    led.unplot(x, y - 1)
    led.unplot(x, y + 1)
    x += 1
    if x >= 5:
        x = 0
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_b():
    global y
    led.unplot(x, y)
    led.unplot(x + 1, y)
    led.unplot(x - 1, y)
    led.unplot(x, y - 1)
    led.unplot(x, y + 1)
    y += 1
    if y >= 5:
        y = 0
input.on_button_pressed(Button.B, on_button_pressed_b)

def on_forever():
    led.plot(x, y)
    led.plot(x + 1, y)
    led.plot(x - 1, y)
    led.plot(x, y - 1)
    led.plot(x, y + 1)
basic.forever(on_forever)
